package com.gzx.plugin.data.wxjk.sync.controller;

import com.alibaba.fastjson.JSON;
import com.gzx.plugin.data.wxjk.sync.DataConstant;
import com.gzx.plugin.data.wxjk.sync.service.DdzwxxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单账务信息推送接口
 */
@RestController
@RequestMapping("/data/receive/wxjk")
@Slf4j
public class DdzwxxController {

    @Autowired
    private DdzwxxService ddzwxxService;

    @PostMapping(value = "/ddzwxx", produces = {"application/json;charset=UTF-8"}, consumes = {"application/json;charset=UTF-8"})
    public String ddzwxx(@RequestBody String req) {
        log.info("接收维信金科订单账务信息数据： {}", req);
        //返回给接口调用方组装报文的map，json返回
        Map<String, String> resultMap = new HashMap<>();
        try {
            Boolean flag = ddzwxxService.save(req);
            if (flag) {
                resultMap.put(DataConstant.CODE, DataConstant.ZERO);
                resultMap.put(DataConstant.MESSAGE, "接收成功");
            } else {
                resultMap.put(DataConstant.CODE, DataConstant.ONE);
                resultMap.put(DataConstant.MESSAGE, "接收诉讼数据失败");
            }

        } catch (Exception e) {
            log.error("save db error:", e);
            resultMap.put(DataConstant.CODE, DataConstant.ONE);
            resultMap.put(DataConstant.MESSAGE, "接收诉讼数据失败");
        }
        return JSON.toJSONString(resultMap);
    }
}
